﻿@{
    ViewBag.Title = "CompanyInfoAdd";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@{
    string Id = ViewData["Id"].ToString();//公司ID(供应商)
    string action = ViewData["action"].ToString();
    string width = ViewData["width"].ToString();
}

<div class="mod_dialog" style="display: block; margin-top: @width; left: 0px">
    <form id="frmAccount" class="layui-form" lay-filter="frmAccount">
        <div class="hd">
            @{
                if (action == "add")
                {
                    <h3>添加供应商信息</h3>
                }
                else
                {
                    <h3>修改公司信息</h3>
                }
            }
        </div>
        <div class="bd">
            <div class="form clearfix nouse" data-col="0">

                <ul class="clearfix">
                    <li>
                        <label class="label">主体公司名称：</label>
                        <div class="inptxt" style="width:200px;">
                            <p></p>
                            <select name="ADD_COMPANY_ID" lay-filter="ADD_COMPANY_ID"
                                    class="layui-inline" style="max-height:200px">
                                @{
                                    foreach (var companyinfo in Model)
                                    {
                                        <option value="@companyinfo.COMPANY_ID">@companyinfo.COMPANY_NAME</option>
                                    }
                                }
                            </select>
                        </div>

                    </li>
                    <li>
                        <label class="label">公司名称：</label>
                        <div class="inptxt">
                            <p></p>
                            <input type="text" name="COMPANY_FULLNAME" lay-filter="COMPANY_FULLNAME" required lay-verify="required" autocomplete="off" class="layui-input">
                        </div>

                    </li>
                    <li>
                        <label class="label">公司简称：</label>
                        <div class="inptxt">
                            <p></p>
                            <input type="text" name="COMPANY_NAME" lay-filter="COMPANY_NAME" required lay-verify="required" autocomplete="off" class="layui-input">
                        </div>

                    </li>
                    <li>
                        <label class="label">公司联系人：</label>
                        <div class="inptxt">
                            <p></p>
                            <input type="text" name="COPANNY_CHARGE" lay-filter="COPANNY_CHARGE" required lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                        
                    </li>
                    <li>
                        <label class="label">联系电话：</label>
                        <div class="inptxt">
                            <p></p>
                            <input type="text" name="COMPANY_PHONE" lay-filter="COMPANY_PHONE" required lay-verify="required" autocomplete="off" class="layui-input">
                        </div>

                    </li>
                    <li>
                        <label class="label">所在城市：</label>
                        <div class="inptxt">
                            <p></p>
                            <input type="text" name="COMPANY_CTIY" lay-filter="COMPANY_CTIY" required lay-verify="required" autocomplete="off" class="layui-input">
                        </div>

                    </li>
                </ul>

            </div>

        </div>
        <div class="fd">
            <div class="load_btn">
                @{
                    if (action == "edit")
                    {
                        <button class="btn_green_m" id="btnEdit" lay-submit lay-filter="btnEdit">保存修改</button>
                        <button class="btn_gray_m" id="btnCancel">取消修改</button>
                    }
                    else if (action == "add")
                    {
                        <button class="btn_green_m" id="btnAdd" lay-submit lay-filter="btnAdd">保存添加</button>
                        <button class="btn_gray_m" id="btnCancel">取消添加</button>

                    }

                }
                @*<button class="btn_green_m" id="btnEdit" lay-submit lay-filter="btnEdit">保存修改</button>
                <button class="btn_gray_m" id="btnCancel">取消修改</button>*@
            </div>
        </div>
    </form>

</div>
<script type="text/javascript">
    $(function () {
            $.ajax({
                url: "/Setting/GetCompanyById/@Id",
                type: "get",
                dataType: "json",
                success: function (data) {
                    var form = layui.form;
                    form.val("frmAccount", data);
                    form.render(); //刷新select选择框渲染
                }
            });
        var form = layui.form;
        form.render(); //刷新select选择框渲染

        form.on('submit(btnEdit)', function (data) {
            var account = $.extend(data.field, { COMPANY_ID: "@Id" });
            com.ajax({
                url: "/Setting/EditCompany", type: "post", dataType: "json", data: account, success: function (data) {
                    parent.location.reload();
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }
            });
            return false;
        });

        form.on('submit(btnAdd)', function (data) {
            var account = data.field;
            //alert(JSON.stringify(account));
            com.ajax({
                url: "/Setting/AddCompanySupplier", type: "post", dataType: "json", data: account, success: function (data) {
                    if (data.state == "success") {
                        if ("@action" == "add") {

                            layer.confirm('供应商添加成功！客服维护账号admin！！！', {
                                btn: ['确定']
                            }, function () {
                                //parent.parent.$("#infoList").datagrid("load");
                                parent.parent.location.reload();
                                var index1 = parent.parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.parent.layer.close(index1); //再执行关闭

                                parent.$("#infoList").datagrid("load");
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭                   
                            });
                        }
                    }
                    else {
                        layer.alert(data.msg);
                    }
                }
            });
            return false;
        });
    })


        $("#btnCancel").click(function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
            return false;
        });
</script>
